package com.house.framework.utils;

import com.house.exception.CustomException;

import java.util.Objects;

public class AssertUtil {

    private final static int DEFAULT_ERROR_CODE = 10001;

    public static void isTrue(boolean condition, String msg) {
        isTrue(condition, msg, null);
    }

    public static void isTrue(boolean condition, String msg, Integer code) {
        if (condition) {
            return;
        }
        throw Objects.nonNull(code) ? new CustomException(msg, code) : new CustomException(msg,DEFAULT_ERROR_CODE);
    }

    public static <T> void nonNull(T obj, String msg, Integer code) {
        isTrue(Objects.nonNull(obj), msg, code);
    }

    public static <T> void nonNull(T obj, String msg) {
        nonNull(obj, msg, null);
    }

    public static <T> void isNull(T obj, String msg, Integer code) {
        isTrue(Objects.isNull(obj), msg, code);
    }

    public static <T> void isNull(T obj, String msg) {
        isNull(obj, msg, null);
    }
}
